#pragma once

#include <windef.h>
#include <boost/function.hpp>

#include "exports.hpp"




#pragma warning (push)
#pragma warning (disable: 4251)

/**
 * This class simplifies the installation of a keyboard hook.
 * It can be used to intercept keyboard messages.
 * Aimed at simplicity, the class accepts a boost functor that
 * can be bound to anything, even a member function.
 *
 * However, this class may only be used in the main thread of the
 * application. It may, under no circumstances be used in \b any
 * other thread.
 *
 * @warning   do not use this class in multiple threads, it is not thread safe.
 *            The class will do a check in debug builds only and crash on purpose
 *            if the calling thread differs from the main thread.
 */
class HOOKS_API KeyboardHook
{
public:

	typedef boost::function<void (int,WPARAM,LPARAM)> KeyboardProc;

private:

	KeyboardProc m_keyboardProc;

public:

	/**
	 * Registers a KeyboardHook.
	 *
	 * @param keyboardProc   functor that is called when a keyboard message is being processed
	 */
	KeyboardHook(const KeyboardProc& keyboardProc);

	/**
	 * Unregisters the KeyboardHook.
	 */
	~KeyboardHook();



	/**
	 * Calls the keyboard procedure. Does not need to be called explicitly by the user, but
	 * it is allowed.
	 */
	void keyboardProc(int message, WPARAM wParam, LPARAM lParam) const;
};
///////////////////////////////////////////////////////////////////////////////////////////////////

#pragma warning (pop)
